package com.tedu.charging.service.device.controller;

import com.tedu.charging.common.pojo.param.UpdateGunStatusParam;
import com.tedu.charging.common.pojo.po.GunStationPO;
import com.tedu.charging.common.pojo.web.ServerResult;
import com.tedu.charging.service.device.pojo.po.GunInfoPO;
import com.tedu.charging.common.pojo.vo.GunInfoVO;
import com.tedu.charging.service.device.service.IGunInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/charging/GunInfo")
@CrossOrigin
public class GunInfoController {

    @Autowired
    IGunInfoService gunInfoService;
    @PostMapping("/updateGunStatus")
    public ServerResult<Boolean> updateGunStatus(@RequestBody UpdateGunStatusParam param){
        GunInfoPO gunInfoPO = new GunInfoPO();
        BeanUtils.copyProperties(param,gunInfoPO);

        boolean result = gunInfoService.updateById(gunInfoPO);
        return new ServerResult(0,"success",result);
    }


    @GetMapping("/selectByStationId")
    public ServerResult<List<GunInfoVO>> selectByStationId(Integer stationId){
        List<GunInfoVO> list = gunInfoService.selectByStationId(stationId);
        return new ServerResult(0,"success",list);
    }

    @GetMapping("/selectByGunId/{gunId}")
    public ServerResult<GunInfoVO> selectByGunId(@PathVariable("gunId") Integer gunId){
        GunInfoVO gunInfoVO = gunInfoService.selectByGunId(gunId);
        return new ServerResult(0,"success",gunInfoVO);
    }

    @GetMapping("/selectStationByGunId/{gunId}")
    public ServerResult<GunStationPO> selectStationByGunId(@PathVariable("gunId") Integer gunId){
        GunStationPO gunStationPO = gunInfoService.selecStationtByGunId(gunId);
        return new ServerResult(0,"success",gunStationPO);
    }
}
